#include "stdafx.h"
#include "AgentSession.h"

AgentSession::AgentSession(void)
{
	memset(&mAddr, 0x0, sizeof(mAddr));
	mAddr.sin_family = AF_INET;
	memset(mHostName, 0x0, sizeof(mHostName));
	mTimestamp = ::time(NULL);
}

AgentSession::~AgentSession(void)
{
}

void AgentSession::Set(const char * ip, WORD port)
{
	mAddr.sin_addr.s_addr = inet_addr(ip);
	mAddr.sin_port = htons(port);
}

void AgentSession::Set(DWORD ip, WORD port)
{
	mAddr.sin_addr.s_addr = htonl(ip);
	mAddr.sin_port = htons(port);
}

void AgentSession::Set(const SOCKADDR_IN &addr)
{
	mAddr = addr;
}

DWORD AgentSession::GetIP() const
{
	return ntohl(mAddr.sin_addr.s_addr);
}

const char * AgentSession::GetStrIP() const
{
	return inet_ntoa(mAddr.sin_addr);
}

WORD AgentSession::GetPort() const
{
	return ntohs(mAddr.sin_port);
}

const SOCKADDR_IN & AgentSession::GetAddr() const
{
	return mAddr;
}

const char * AgentSession::GetHostName() const
{
	return mHostName;
}

void AgentSession::SetHostName(const char *hostname)
{
	strncpy(mHostName, hostname, sizeof(mHostName));
}

bool AgentSession::operator == (const AgentSession &ref)
{
	return GetIP() == ref.GetIP() && GetPort() == ref.GetPort();
}
